<?php
session_start();
/*
  CSS Tham
 */

$pathinfo = pathinfo(__FILE__);
preg_match('/.+(?=wp-content)/', $pathinfo['dirname'], $match);
$pathNeeded = preg_replace('/\ /', '/', $match[0]);
require_once($pathNeeded . 'wp-load.php'); //refer to wp-load to use instruction
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
global $post, $wpdb,$table_user;
$table_user = "travel_users";

if (isset($_REQUEST['username'])) {
    $username = $_REQUEST['username'];
    $sql1 = "SELECT * FROM `".$table_user."` WHERE user_login = '" . $username . "'";
    $myrows = $wpdb->get_results($sql1);
    //print_r($myrows);
    $n = count($myrows);
    if ($n > 0) {
	echo '1';
    } else {
	echo '0';
    }
}
if(isset($_REQUEST['emailexist'])){
    
	   $emai = $_REQUEST['emailexist'];
            $sql1 = "SELECT * FROM `".$table_user."` WHERE user_email = '" . $emai . "'";
            $myrows = $wpdb->get_results($sql1);
           // print_r($sql1);
            $n = count($myrows);
            if ($n > 0) {
                echo '1';
            } else {
                echo '0';
            }
	
}
if(isset($_REQUEST['emailexist2'])){
	$emai = $_REQUEST['emailexist2'];
        $sql1 = "SELECT * FROM `".$table_user."` WHERE user_email = '" . $emai . "' and ID <> " . $_SESSION['userlogin']['ID'];
       // echo $sql1;
        $myrows = $wpdb->get_results($sql1);
        //print_r($myrows);
        $n = count($myrows);
        if ($n > 0) {
            echo '1';
        } else {
            echo '0';
        }
	
}

if (isset($_REQUEST['username2'])) {

    $username = $_REQUEST['username2'];
    $sql1 = "SELECT * FROM `".$table_user."` WHERE user_login = '" . $username . "' and ID <> " . $_SESSION['userlogin']['ID'];
    $myrows = $wpdb->get_results($sql1);
    //print_r($myrows);
    $n = count($myrows);
    if ($n > 0) {
	echo '1';
    } else {
	echo '0';
    }
}
if (isset($_REQUEST['logout'])) {    
    unset($_SESSION['userlogin']);
}
if (isset($_REQUEST['addresstest'])) {
   
    $address = $_REQUEST['addresstest'];
    $address = urlencode($address);
	
    $pointer = Maplocation::getPointByAddress($address);	
    
    echo $pointer['lat'] . "," . $pointer['lng'];
}
if (isset($_REQUEST['id_country'])) {
    $id_country = $_REQUEST['id_country'];
    $country = new Country;
    $ds = $country->get_all_state_by_id_country($id_country);
    echo $ds;
}
if(isset($_REQUEST['delete_idlocation']))
{
	$idlocation =  $_REQUEST['delete_idlocation'];
	$sql = 'DELETE FROM `gorave_locate_installation` WHERE `locate_installation_id` ='.$idlocation;
	$wpdb->query($sql);
	
	
    // echo $idlocation;
}


